import pygame

pygame.init()

WIN_WIDTH = 400
WIN_HEIGHT = 600

window = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
window.fill((255, 255, 255))
pygame.display.set_caption('移动的球')

pygame.display.flip()

# 画一个小球
x, y = 100, 20
r = 20
y_step = 1
pygame.draw.circle(window, (234, 125, 213), (x, y), r)
pygame.display.update()

num = 0
while True:

    num += 1
    if num % 10 == 0:
        pygame.draw.circle(window, (255, 255, 255), (x, y), r)
        y += y_step
        if y >= WIN_HEIGHT - r:
            y_step = y_step * -1
        elif y <= r:
            y_step = y_step * -1
        pygame.draw.circle(window, (234, 125, 213), (x, y), r)
        pygame.display.update()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
